package org.hs.im.forensicj.view.action;

import java.awt.event.ActionEvent;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.ParameterBlock;

import javax.media.jai.JAI;
import javax.media.jai.RenderedOp;
import javax.media.jai.operator.MedianFilterDescriptor;

import org.hs.im.forensicj.Application;
import org.hs.im.forensicj.ForensicJ;
import org.hs.im.forensicj.view.ImageViewer;

public class DenoiseMedianAction extends AbstractForensicJAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	public DenoiseMedianAction(){
		super( "Median" );
	}
	
	
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		Application app = ForensicJ.getInstance().getApplication();
		ImageViewer viewer = app.getActiveImageViewer();
		
		RenderedImage image = viewer.getImage();
		
		ParameterBlock params = new ParameterBlock();
		params.setSource(image, 0);
		params.add( MedianFilterDescriptor.MEDIAN_MASK_SQUARE );
		params.add(3);
		
		RenderedOp result = JAI.create("MedianFilter", params);
		
		viewer.setImage(result);
	}

}
